<template>
  <div id="mainRD" style="height: 300px;width: 100%;"></div>
</template>

<script>
import * as echarts from 'echarts';
import axios from "axios";

export default {
  name: 'adminStatisticsRightDown',
  methods: {
    fetchResumes() {
      axios.get(`/api/resume/getResumeJobResponse/all`)
          .then((response) => {
            const data = response.data;
            const resumeCountByDate = {};
            data.forEach((item) => {
              const date = new Date(item.deliverTime);
              const year = date.getFullYear();
              const month = String(date.getMonth() + 1).padStart(2, '0');
              const day = String(date.getDate()).padStart(2, '0');
              const formattedDate = `${year}-${month}-${day}`;
              if (resumeCountByDate[formattedDate]) {
                resumeCountByDate[formattedDate]++;
              } else {
                resumeCountByDate[formattedDate] = 1;
              }
            });
            const xAxisData = Object.keys(resumeCountByDate);
            const yAxisData = Object.values(resumeCountByDate);
            // 调用更新图表的方法，将新数据传入
            this.updateChart(xAxisData, yAxisData);
          })
          .catch((error) => {
            console.log(error);
          });
    },
    updateChart(xAxisData, yAxisData) {
      const chartDom = document.getElementById('mainRD');
      if (chartDom) {
        const myChart = echarts.init(chartDom);
        const option = {
          xAxis: {
            type: 'category',
            data: xAxisData
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: yAxisData,
              type: 'line'
            }
          ]
        };
        myChart.setOption(option);
      }
    }
  },
  mounted() {
    this.fetchResumes();
  }
}
</script>

<style scoped>
</style>
